package restdom.validation;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;
import org.springframework.validation.Errors;

import restdom.validation.impl.DefaultValidationSupport;

/**
 * 
 * @deprecated
 */
@Deprecated
@Aspect
public class ValidationIntroduction {

	@DeclareParents(value = "restdom.dao.impl.*+", defaultImpl = DefaultValidationSupport.class)
	public static ValidationSupport mixin;

	@Before(value = "execution(* restdom.dao.impl.*.create(..)) &&"
			+ "this(mixin) && args(instance)", argNames = "mixin,instance")
	public void validateOnCreate(ValidationSupport mixin, Object instance) {
		Errors errors = mixin.validateOnCreate(instance);
		if (errors.hasErrors()) {
			throw new ValidationFailedException(errors);
		}
	}

	@Before(value = "execution(* restdom.dao.impl.*.update(..)) &&"
			+ "this(mixin) && args(instance)", argNames = "mixin,instance")
	public void validateOnUpdate(ValidationSupport mixin, Object instance) {
		Errors errors = mixin.validateOnUpdate(instance);
		if (errors.hasErrors()) {
			throw new ValidationFailedException(errors);
		}
	}
}
